#ifndef CMATRIX3X3_H
#define CMATRIX3x3_H

/* Copyright (C) 2011 Riccardo Marson

   This file is part of OpenPool, an open-source game of pool.

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   RICCARDO MARSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
   AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  See Readme.rtf for further information.

*/

#include <iostream>

#include "CVector3.h"

//! \brief 3x3 square matrix. 
class CMatrix3x3
{
public:

    CMatrix3x3(); //! empty constructor
    CMatrix3x3(float *raw_data); //! constructor. vector components are initialised with x, y, z
    CMatrix3x3(const CMatrix3x3 &source); //! copy constructor
    ~CMatrix3x3(); //! deconstructor

    float& operator() (const unsigned short i, const unsigned short j); //! outputs mData[i*3 + 3]. i and j must be between 0 and 3.
    CMatrix3x3 operator+ (CMatrix3x3 matrix); //! element-wise sum of 2 matrices
    CMatrix3x3 operator+ (const float scalar); //! sum of matrix and scalar constant
    CMatrix3x3 operator- (CMatrix3x3 matrix); //! element-wise subtraction of 2 matrices
    CMatrix3x3 operator- (const float scalar); //! subtraction of scalar constant
    CMatrix3x3 operator* (CMatrix3x3 matrix); //! matrix (rowsxcolumns) multiplication
    CMatrix3x3 operator* (const float scalar); //! multiplication by a scalr value
	CVector3 operator* (CVector3 vector); //! multiplication by a 3d vector
    CMatrix3x3& operator= (CMatrix3x3 matrix); //! equality test
    bool operator== (const CMatrix3x3 matrix);//! inequality test

	void LoadIdentity();
    CMatrix3x3 Transpose(); //! returns the transpose of the current matrix
    CVector3 GetRow(const unsigned short i); //! returns the ith row as a CVector3
	CVector3 GetColumn(const unsigned short j); //! returns the jth columns as a CVector3
    float* Data(); //! return the pointer to mData

    friend std::ostream & operator << (std::ostream &out, CMatrix3x3 &mat);
    
private:

    float mData[9];

};


#endif // CMATRIX3x3_H
